package com.banyuan.controller;

import com.banyuan.domain.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@Controller
public class DemoController {

    @RequestMapping("/hello1")
        public String hello1(String name) {
        System.out.println(name);
        return "success";
    }

    @RequestMapping("/hello2")
    public String hello2(Person person) {
        System.out.println(person);
        return "success";
    }

    @RequestMapping("/hello3")
    public String hello3(@RequestParam(value = "username",required = false,defaultValue = "zhangsan") String name ) {
        System.out.println(name);
        return "success";
    }

    @RequestMapping("/hello4")
    public String hello4(Date date) {
        System.out.println(date);
        return "success";
    }

    @RequestMapping("/hello5/{name}")
    public String hello5(@PathVariable("name") String name) {
        System.out.println(name);
        return "success";
    }

    @RequestMapping("/hello6")
    public ModelAndView hello6() {
        ModelAndView mv = new ModelAndView("success");
        Person person = new Person();
        person.setName("zhangsan");
        person.setAge(18);
        person.setDate(new Date());
        mv.addObject("person",person);

        return mv;
    }

}
